package org.tedu.day08springmvc.controller;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.tedu.day08springmvc.mapper.UserMapper;
import org.tedu.day08springmvc.pojo.dto.UserDTO;
import org.tedu.day08springmvc.pojo.entity.User;

import java.util.Date;

@Controller
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/users/reg")
    @ResponseBody
    public String reg(UserDTO userDTO) {
        User user = new User();
        BeanUtils.copyProperties(userDTO, user);
        user.setCreated(new Date());
        int num = userMapper.insertUser(user);
        return num > 0 ? "插入成功" : "插入失败";
    }

    @RequestMapping("/users/delete")
    @ResponseBody
    public String delete(UserDTO userDTO) {

        return "";
    }

    @RequestMapping("/users/update")
    @ResponseBody
    public String update(UserDTO userDTO) {

        return "更新成功";
    }
}
